﻿using System;
using HttpApiGateway.Model;
using RpcClient;
using RpcHelper;
using Wedonek.RpcStore.Gateway.Interface;
using Wedonek.RpcStore.Gateway.Model;
using Wedonek.RpcStore.Service.Interface;
using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Gateway.Service
{
    internal class AutoTaskService : IAutoTaskService
    {
        private readonly IAutoTaskCollect _AutoTask = null;

        public AutoTaskService(IAutoTaskCollect task)
        {
            this._AutoTask = task;
        }

        public Guid AddAutoTask(AddAutoTask task)
        {
            AutoTask add = task.ConvertMap<AddAutoTask, AutoTask>();
            add.VerNum = Tools.GetRandom();
            return this._AutoTask.Add(add);
        }

        public void DropAutoTask(Guid id)
        {
            AutoTaskList task = this._AutoTask.Get(id);
            this._AutoTask.Drop(task);
        }

        public AutoTaskList GetAutoTask(Guid id)
        {
            return this._AutoTask.Get(id);
        }

        public AutoTaskDatum[] QueryTask(PagingParam<QueryTaskParam> param, out long count)
        {
            return this._AutoTask.Query(param.Param, param.ToBasicPaging(), out count);
        }

        public void SetAutoTask(SetAutoTask param)
        {
            AutoTaskList task = this._AutoTask.Get(param.Id);
            this._AutoTask.Set(task, param.Datum);
        }
    }
}
